package com.shujia.spark.mllib

import java.io.StringReader

import org.wltea.analyzer.core.{IKSegmenter, Lexeme}

import scala.collection.mutable.ListBuffer

object IK {
  def main(args: Array[String]): Unit = {

    val str = "数加学院牛逼"

    val words: List[String] = fit(str)

    println(words)
  }

  def fit(str: String): List[String] = {

    val words = new ListBuffer[String]

    val reader = new StringReader(str)

    val segmenter = new IKSegmenter(reader, true)

    var lexeme: Lexeme = segmenter.next()

    while (lexeme != null) {

      val word: String = lexeme.getLexemeText


      words += word

      lexeme = segmenter.next()
    }

    words.toList
  }
}
